package com.lzw.cpvideoplayer.ulit;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class Permission {
    public static  int REQUEST_CODE = 100;
    private static final String[] permission = {
            Manifest.permission.READ_SMS,
            Manifest.permission.RECEIVE_SMS

    };
    private static final String TAG = "Permission";
    private List<String> permissionList = new ArrayList<>();
    public void checkPermission(Activity activity){
        Log.e(TAG, "checkPermission: "+Build.VERSION.SDK_INT );
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

            //查询app是否具备权限
            for (String permiss : permission) {

                //PackageManager.PERMISSION_GRANTED 查询的权限已经获取到的话会返回这个
                if (ActivityCompat.checkSelfPermission(activity,permiss)!=PackageManager.PERMISSION_GRANTED){
                    //我们的app不具备这个权限
                   // ActivityCompat.requestPermissions(activity,permission,100);
                    Log.e(TAG, "checkPermission: "+permiss );
                    permissionList.add(permiss);
                }else{
                    Log.e(TAG, "checkPermission: 已全部取得权限" );
                }
            }
            if (permissionList.size()>0){
                String[] permiss =permissionList.toArray(new String[]{});

               //  ActivityCompat.requestPermissions(activity,permiss,REQUEST_CODE);

            }

        }
    }
}
